<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>预约</title>

    <link rel="stylesheet" href="../css/page-health-order.css" />

    <script src="../js/axios-0.18.0.js"></script>
    <script src="../js/vue.js"></script>
</head>

<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
    <div id="app">
        <!-- 页面头部 -->
        <div class="top-header">
            <span class="f-left" onclick="goBack()"><i class="icon-back"></i>返回</span>
            <span class="center">千锋健康</span>
            <span class="f-right"><i class="icon-more"></i></span>
        </div>
        <!-- 页面内容 -->
        <div class="contentBox">
            <div class="select-drop">
                <select name="filter" id="sex" @change="sexInt()" v-model="sex">
                    <option>不限</option>
                    <option>男</option>
                    <option>女</option>
                </select>
            </div>

            <div class="list-column1">
                <ul class="list">
                    <li class="list-item" v-for="setmeal in setmeals">
                        <a :href="'health-setmealDetail.html?sid=' + setmeal.id" class="link-page">
                        <img class="img-object f-left" :src="'http://localhost:8081/setmeal/img?name=' + setmeal.img+'&token='+srcToken" alt="">
                <div class="item-body">
                    <h4 class="ellipsis item-title">{{setmeal.name}}</h4>
                    <p class="ellipsis-more item-desc">{{setmeal.remark}}</p>
                    <p class="item-keywords">
                        <span v-if="setmeal.sex == 0">男女通用</span>
                        <span v-if="setmeal.sex == 1">男</span>
                        <span v-if="setmeal.sex == 2">女</span>
                        <span>{{setmeal.age}}</span>
                    </p>
                    <p class="item-link">
                        <span class="mui-btn item-btn">查看</span>
                    </p>
                </div>
                        </a>
                    </li>
                </ul>
            </div>

        </div>
    </div>

    <script>

        function getUrlParams (name) {
            let url = window.location.href;
            let tstr = url.substring(url.indexOf('?') + 1).split('&');
            let result = {};
            tstr.forEach((item) => {
                let res = item.split('=');
                result[res[0]] = res[1];
            });
            return result[name];
        };

        function goBack() {
            window.history.back();
        }

        let sid = getUrlParams("sid");

        new Vue({
            el:"#app",
            data:{
                setmeals:[],
                sex:"",
                srcToken:localStorage.getItem("security_token")
            },
            methods:{
                findAll(){
                    let token = localStorage.getItem("security_token");
                    if (!token){
                        token = "";
                    }
                    axios({
                        url:"http://localhost:8081/setmeal",
                        method:"GET",
                        headers:{
                            token:token
                        }
                    }).then(resp=>{
                        let r = resp.data;
                        if (r.code == 200){
                            this.setmeals = r.data;
                        }else if (r.code == 401){
                            alert(r.message);
                            location.href = "health-login.html";
                        }else {
                            alert(r.message)
                        }
                    });
                },
                sexInt(){
                    let token = localStorage.getItem("security_token");
                    if (!token){
                        token = "";
                    }
                    axios({
                        url:`http://localhost:8081/setmeal/sex/${this.sex}`,
                        method:"GET",
                        headers:{
                            token:token
                        }
                    }).then(resp=>{
                        let r = resp.data;
                        if (r.code == 200){
                            if (r.data.length >= 1){
                                this.setmeals = r.data;
                            }else {
                                alert("没有套餐")
                                this.setmeals = "";
                            }
                        }else if (r.code == 401){
                            alert(r.message);
                            location.href = "health-login.html";
                        }else {
                            alert(r.message)
                        }
                    });
                }
            },
            mounted(){
                this.findAll();
            }
        })
    </script>
</body>